<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/commons/cssinclude.jsp"></jsp:include>
<jsp:include page="/jsp/commons/scriptinclude.jsp"></jsp:include>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>晶品科技信息管理系统-配置管理</title>

</head>
<body>
	<%--<jsp:include page="/jsp/commons/top.jsp"></jsp:include> --%>
	<div class="mainbox">

		<form method="post" action="${ctx}/dispatch/dispatchAction!add.do"
			id="frmCustomerAdd">
			<input type="hidden" id="hbActionType" value="${actionType}" />
			<div class="main_content">
				<%--<%@include file="/jsp/commons/leftMenu.jsp"%> --%>
				<div class="main_right">
					<!--面包屑 begin-->
					<div class="main_rightbox">
						<div class="ec_crumb_kc">
							<span><a class="icon_up" href="#">上一页</a><a
								class="icon_index" href="#">首页</a></span>当前位置：首页&nbsp;&gt;&nbsp;配置管理&nbsp;&gt;&nbsp;客户信息&nbsp;&gt;&nbsp;<em>新增</em>
						</div>
					</div>
					<!--基本信息 begin-->
					<div class="ty_border">
						<div class="ty_head">
							<span class="icon4"></span>客户信息
						</div>
						<div class="sx_body">
							<dl class="clearfix">
								<dt style="display: none;">客户信息</dt>

								<dd>
									<label class="name">客户级别：</label><span class="toname">   <select id="level"
										name="customer.level"
										style="border: 1px solid #DDDDDD; color: #999999; float: right; height: 29px; line-height: 29px; padding-left: 5px; width: 218px;">
										<option value="">---请选择---</option>
										<option <c:if test="${customer.level eq 1}"> selected="selected"</c:if>  value="1">一级</option>
										<option <c:if test="${customer.level eq 2}"> selected="selected"</c:if> value="2">二级</option>
										<option <c:if test="${customer.level eq 3}"> selected="selected"</c:if> value="3">三级</option>
									</select>
									</span>
									<div class="fl">
										<em id="levelTip"></em>
									</div>
								</dd>
								
								<dd id="parent_dd">
									<label class="name">父级客户：</label><span class="toname">   <select id="parent"
										name="customer.parent"
										style="border: 1px solid #DDDDDD; color: #999999; float: right; height: 29px; line-height: 29px; padding-left: 5px; width: 218px;">
										<option value="">---请选择---</option>
									</select>
									</span>
									<div class="fl">
										<em id="levelTip"></em>
									</div>
								</dd>
								
								<dd>
									<label class="name">客户类别：</label><span class="toname">   <select id="customerType"
										name="customer.customerType"
										style="border: 1px solid #DDDDDD; color: #999999; float: right; height: 29px; line-height: 29px; padding-left: 5px; width: 218px;">
										<option value="">---请选择---</option> 
										<c:forEach items="${lstCustomerType }" var="sys"> 
											<option <c:if test="${customer.customerType eq  sys.code}">selected="selected"</c:if>  value="${sys.code}">${sys.value }</option>
										</c:forEach>
										 
									</select>
									</span>
									<div class="fl">
										<em id="repairDateTip"></em>
									</div>
								</dd>
								
								<dd>
									<label class="name">客户名称：</label><span class="toname"> <input
										type="text" value="${customer.name }" id="name" name="customer.name"
										title="客户名称" 
										 class="winput3" />
									</span>
									<div class="fl">
										<em id="repairDateTip"></em>
									</div>
								</dd>
								
								<dd>
									<label class="name">路线：</label><span class="toname"> 
								   <select id="pathId"
										name="customer.pathId"
										style="border: 1px solid #DDDDDD; color: #999999; float: right; height: 29px; line-height: 29px; padding-left: 5px; width: 218px;">
										 
										<option value="">---请选择---</option>
										<c:forEach items="${lstPath }" var="path" >  
										<option <c:if test="${customer.pathId eq path.value}">selected="selected"</c:if>  value="${path.value }">${path.name}</option>
										</c:forEach>
									</select>
									
									</span>
									<div class="fl">
										<em id="repairDateTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">联系人：</label><span class="toname"> <input
										type="text" value="${customer.linkman }" id="linkman" name="customer.linkman"
										title="联系人"  
										class="winput3" />
									</span>

									<div class="fl">
										<em id="linkmanTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">联系人电话：</label> <span class="toname">
										<input type="text" id="contactPhone" value="${customer.contactPhone }"
										name="customer.contactPhone" title="联系人电话"
										 
										class="winput3" />
									</span>
									<div class="fl">
										<em id="contactPhoneTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">最高领导：</label><span class="toname"><input
										type="text" id="topLeader" value="${customer.topLeader }" name="customer.topLeader"
										title="最高领导" 
										 class="winput3" /></span>
									<div class="fl">
										<em id="topLeaderTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">最高领导电话：</label><span class="toname">

										<input type="text" id="topLeaderPhone" value="${customer.topLeaderPhone }"
										name="customer.topLeaderPhone" title="最高领导电话"
										 
										class="winput3" />
									</span>
									<div class="fl">
										<em id="topLeaderPhoneTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">状态：</label>
									<span class="toname"> 
									
									<select id="state"
										name="customer.state"
										style="border: 1px solid #DDDDDD; color: #999999;   height: 29px; line-height: 29px; padding-left: 5px; width: 225px;">
										<option value="">---请选择---</option>
										<option <c:if test="${customer.state eq '0'}">selected="selected"</c:if>  value="0">无效</option>
										<option <c:if test="${customer.state eq '1'}">selected="selected"</c:if> value="1">有效</option>
									</select>
									 
									</span>

									<div class="fl">
										<em id="stateTip"></em>
									</div>
								</dd>

								<dd>
									<label class="name">备注：</label><span class="toname"> <textarea
											rows="30" cols="100" id="warranty" name="customer.note"
											title="备注"  
											class="winput3">${customer.note }</textarea>
									</span>

									<div class="fl">
										<em id="noteTip"></em>
									</div>
								</dd>

							</dl>
						</div>
					</div>


					<!--保存取消 begin-->
					<div class="baocun">
						<button type="button" id="btnQuit" class="gybg qxBtn">取消</button>
						<input type="button" id="btnSave" class="gybg saveBtn" value="保存" />
					</div>
				</div>
			</div>
			<c:if test="${actionType eq '1'}">
			<%--隐藏域start --%>
			<input type="hidden" name="customer.id" value="${customer.id}">
			<%--隐藏域end   --%>
			</c:if>
		</form>
	</div>
     
	<!--客户弹出层 begin-->
	<div id="customerDialog" style="display: none">
		<s:action name="categoryAction!queryCategorySortList"
			executeResult="true" namespace="/category">
		</s:action>

	</div>

	<!-- JQ -->

	<script type="text/javascript">
	     $(function(){
	    	 $("#parent_dd").hide();
	    	 //判断页面为修改页面
	    	 if($("#hbActionType").val()==1){
	    		 <c:if test="${not empty  customer.level}">
	    		 var jsLevel=${customer.level};
	    		 if(jsLevel!=1){
	    			 $("#parent_dd").show();
	    		 }
	    		 var jsParent="";
	    		 <c:if test="${not empty  customer.parent}">
	    		 jsParent=${customer.parent };
	    		 </c:if>
	    		 showCustomerByLevel(jsLevel-1,jsParent==null?"":jsParent);
	    		 </c:if>
	    	 }
	     });
	   
	    //根据客户级别显示父级客户
	    $("#level").change(function(){
	    	if($(this).val()==1||$(this).val()==0){
	    		$("#parent_dd").hide();
	    	}else if($(this).val()==2){
	    		showCustomerByLevel($(this).val()-1,"");
	    		$("#parent_dd").show();
	    	}else if($(this).val()==3){
	    		showCustomerByLevel($(this).val()-1,"");
	    	    $("#parent_dd").show();
	    	}
	    });
	    
	    //根据等级请求客户列表
	    function showCustomerByLevel(levelVal,selectedVal){
	    	$.post(
		     		 "${ctx}/customer/customerAction!queryCustomers.action", 
		 				{random:Math.random(),"customer.level":levelVal}, 
		 				function(data){
		 					var result="";
		 					var msg=JSON.parse(data);
		 					if(msg.flag=="success") {
		 						
		 						$(msg.data).each(function(index,elment){
		 							result+="<option value=\"";
		 							result+=elment.id;
		 							result+="\"";
		 							if(selectedVal!=""&&selectedVal==elment.id){
		 								result+="selected=\"selected\"";
		 							}
		 							result+=">";
		 						    result+= elment.name;
		 							result+="</option>";
		 						});
		 						$("#parent").empty(); 
		 						$("#parent").append(result);   //为Select追加一个Option(下拉项)
		 					}
		 					if(msg.flag=="error"){
		 						alert(data.errorMsg);
		 					}
		 					 
		 				}
		      
		        );
	    }
	
		//异步加载客户名称
		$("#btnCustomerName").click(function() {
			var url = "${ctx}/dispatch/dispatchAction!initCustomer.action";
			var params = {
				"random" : Math.random()
			};
			$.ajax({
				url : url,
				type : 'post',
				data : params,
				async : false,
				dataType : 'json',
				success : function(data) {
					$("#customerDialog").html(data);
				},
				error : function() {
					alert("系统错误");
					queryCategory();
				}
			});
		});

		//根据状态为来决定是增加还是修改
		$("#btnSave")
				.click(
						function() {
							var strActionType = $("#hbActionType").val();
							if (strActionType != "") {
								if (strActionType == 0) {
									//新增操作
									//验证编码
									var vCode = $("#name").val();
									if (vCode == "") {
										$("#nameTip").html(
												setPrompt("onError",
														"客户名称不能为空，请输入",
														"${ctx}"));
										$("#name").focus();
									} else {

										$("#frmCustomerAdd").attr("action","${ctx}/customer/customerAction!addCustomer.action");
										$("#frmCustomerAdd").submit();

									}
								} else if (strActionType == 1) {
									//修改操作
									$("#frmCustomerAdd").attr("action","${ctx}/customer/customerAction!updateCustomer.action");
									$("#frmCustomerAdd").submit();
								} else {
									alert("系统错误，请联系系统管理员！");
								}
							} else {
								alert("系统错误，请联系系统管理员！");
							}
						});

		//取消事件
		$("#btnQuit").click(function(){
			art.dialog.confirm('你确认放弃页面操作，返回列表？', function(){
				location.href ="${ctx}/customer/customerAction!listInit.action";
			}, function(){
			     
			});
		});
		 
		/**
		 *绑定值改变事件
		 */
		$("#sysparaCode").change(
				function() {
					$("#sysparaCodeTip").html(
							setPrompt("onLoad", "正在验证数据，请稍等", "${ctx}"));
					codeValidator($("#sysparaCode").val(), "Y");
				});

		$(".ctnGdpOptionPanel li").hover(function() {
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
		});
		$(".arrowname").click(function() {
			var domUl = $(this).parent().find(".ctnGdpOptionPanelMask");
			var domArrow = $(this).find("span.arrowdown");
			if (domArrow.hasClass("arrowUp")) {
				domArrow.removeClass("arrowUp");
				domUl.show();
			} else {
				domArrow.addClass("arrowUp");
				domUl.hide();
			}
		});
	</script>
</body>
</html>